﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;


namespace NJCORS.forms
{
    public partial class AddLandInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                try
                {
                    BLL.AttributeInfo bllmode = new BLL.AttributeInfo();
                    DataSet ds = bllmode.GetList("Enabled=1");
                    ddlAttributeName.DataSource = ds;
                    ddlAttributeName.DataTextField = "AttributeName";
                    ddlAttributeName.DataValueField = "AttributeID";
                    ddlAttributeName.DataBind();
                }
                catch (Exception ex)
                {
                    ShowMessage(false, ex.Message);
                }
            }
            diverrormsg.Style.Add("display", "none");
        }

        protected void btnadd_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                //if (txbLandName.Text.Length < 1)
                //{
                //    throw new Exception("请填写土地名称！");
                //}
                if (txbLandScope.Text.Length < 1)
                {
                    throw new Exception("请填写土地范围！");
                }
                BLL.LandInfo bli = new BLL.LandInfo();
                Model.LandInfo mli = new Model.LandInfo();
                mli.LandName = txbLandName.Text.Trim();
                mli.LandScope = txbLandScope.Text.Trim();
                mli.AttributeID = Convert.ToInt32(ddlAttributeName.SelectedValue);
                mli.Enabled = true;
                bli.Add(mli);

                ShowMessage(true, "添加土地成功！");
            }
            catch (System.Exception ex)
            {
                ShowMessage(false, ex.Message);
            }
        }

        protected void ShowMessage(bool issuccessful, string message)
        {
            diverrormsg.Style.Add("display", "block");
            if (issuccessful == true)
            {
                diverrormsg.Style.Add("background-color", "#CCFF99");
                diverrormsg.Style.Add("border-color", "#009900");
                diverrormsg.Style.Add("color", "#006600");
                diverrormsg.Style.Add("background-image", "url(../themes/images/successful.gif)");
                lberrormsg.Text = message;
            }
            else
            {
                diverrormsg.Style.Add("background-color", "#ffebe8");
                diverrormsg.Style.Add("border-color", "#dd3c10");
                diverrormsg.Style.Add("color", "#dd3c10");
                diverrormsg.Style.Add("background-image", "url(../themes/images/error.gif)");
                lberrormsg.Text = message;
            }
        }

    }
}
